package configuration

import (
	"encoding/json"
	"kop/modules/configuration/client"
	"kop/util/log"
)

var TreasureItemConfigs map[int32]treasureItemConf

func init() {

	var data []treasureItemConf

	if err := json.Unmarshal(client.Load("ActivityHunt"), &data); err != nil {
		panic(err)
	}

	TreasureItemConfigs = make(map[int32]treasureItemConf, 0)
	for _, v := range data {
		TreasureItemConfigs[v.ItemID] = v
	}

	log.Info("Load ActivityHunt.json success.")
}

type treasureItemConf struct {
	ItemID  int32 // 道具ID
	Type    int32 // 寻宝类型
	Score   int64 // 寻宝积分
	AwardID int32 // 寻宝奖励ID
}

func GetTreasureConfigs(serverID int32) []ActivityConf {

	var n = 开服第N天(serverID)

	var res []ActivityConf

	if n <= Z8 {
		// open server not over 28 day
		for _, v := range treasureList1 {
			if n >= v.BeginDay && n <= v.ShowDay() {
				v.setTime1(serverID)
				res = append(res, v)
			}
		}

	} else {
		// open server over 28 day
		n -= Z8
		var mod = n % Z8
		if mod == 0 {
			mod = Z8
		}
		for _, v := range treasureList2 {
			if mod >= v.BeginDay && mod <= v.ShowDay() {
				v.setTime2(serverID)
				res = append(res, v)
			}
		}
	}

	return res
}
